Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for ystore to be started #43

Merged
merged 2 commits into from
May 7, 2024

Conversation

davidbrochart
Copy link
Collaborator

No description provided.

@davidbrochart davidbrochart added the enhancement New feature or request label May 6, 2024
@@ -135,7 +135,7 @@ def on_message(self, value: Callable[[bytes], Awaitable[bool] | bool] | None):

async def _broadcast_updates(self):
if self.ystore is not None and not self.ystore.started.is_set():
self._task_group.start_soon(self.ystore.start)
await self._task_group.start(self.ystore.start)
Copy link
Collaborator

@jzhang20133 jzhang20133 May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_broadcast_updates method is scheduled as start_soon task still. We could not guarantee that this ystore.start method will run before ystore.start method in DocumentRoom initialize room method. A race condition could happen. We might want to capture exception here in case that ystore task group has already been started.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR doesn't specifically targets the issue you are mentioning, it's just to ensure that the YStore has effectively started (which was not guaranteed with start_soon).
That said, you're raising a good point, as starting a YStore could be done concurrently. A solution would be to have a Lock for a YStore that the user could use like this:

async with ystore.start_lock:
    if not ystore.started.is_set():
        await task_group.start(ystore.start)

I pushed 798120b to use this pattern internally in pycrdt-websocket, and this would have to be used in jupyter-collaboration too.

@davidbrochart davidbrochart merged commit 63cd8a6 into jupyter-server:main May 7, 2024
7 checks passed
@davidbrochart davidbrochart deleted the start-ystore branch May 7, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants